package cn.iocoder.yudao.module.crossborder.order.service.ordercustomer;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.order.controller.admin.ordercustomer.vo.*;
import cn.iocoder.yudao.module.crossborder.order.dal.dataobject.ordercustomer.OrderCustomerDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.order.dal.mysql.ordercustomer.OrderCustomerMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.order.enums.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.crossborder.enums.CrossBorderConstants.*;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerTypeEnum;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerLevelEnum;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerStatusEnum;
import static cn.iocoder.yudao.module.crossborder.enums.CrossBorderConstants.*;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerTypeEnum;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerLevelEnum;
import cn.iocoder.yudao.module.crossborder.order.enums.CustomerStatusEnum;

/**
 * 跨境电商客户信息 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class OrderCustomerServiceImpl implements OrderCustomerService {

    @Resource
    private OrderCustomerMapper orderCustomerMapper;

    @Override
    public Long createOrderCustomer(OrderCustomerSaveReqVO createReqVO) {
        // 插入
        OrderCustomerDO orderCustomer = BeanUtils.toBean(createReqVO, OrderCustomerDO.class);
        orderCustomerMapper.insert(orderCustomer);

        // 返回
        return orderCustomer.getId();
    }

    @Override
    public void updateOrderCustomer(OrderCustomerSaveReqVO updateReqVO) {
        // 校验存在
        validateOrderCustomerExists(updateReqVO.getId());
        // 更新
        OrderCustomerDO updateObj = BeanUtils.toBean(updateReqVO, OrderCustomerDO.class);
        orderCustomerMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderCustomer(Long id) {
        // 校验存在
        validateOrderCustomerExists(id);
        // 删除
        orderCustomerMapper.deleteById(id);
    }

    @Override
        public void deleteOrderCustomerListByIds(List<Long> ids) {
        // 删除
        orderCustomerMapper.deleteByIds(ids);
        }


    private void validateOrderCustomerExists(Long id) {
        if (orderCustomerMapper.selectById(id) == null) {
            throw exception(ORDER_CUSTOMER_NOT_EXISTS);
        }
    }

    @Override
    public OrderCustomerDO getOrderCustomer(Long id) {
        return orderCustomerMapper.selectById(id);
    }

    @Override
    public PageResult<OrderCustomerDO> getOrderCustomerPage(OrderCustomerPageReqVO pageReqVO) {
        return orderCustomerMapper.selectPage(pageReqVO);
    }

}